/**
 * create by young (young2f@outlook.com) on 2020/12/3
 */
'use strict';
const model = require('../base/tModelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmc');
  const json = {
    userCode: { type: 'string' },
    username: { type: String, required: true, desc: '用户名' },
    password: { type: String, required: true, desc: '密码' },
    /**
     * 用户类型：
     * su:
     * admin:管理员
     * user:普通用户
     * vendor:供应商用户
     */
    userType: { type: String, required: true, desc: '用户类型' },
    tenantCode: { type: 'string', required: true, desc: '租户编码' },
    nickname: { type: String, },
    tenantName: { type: 'string' },
    treeId: { type: 'string' },
    createUser: { type: 'string' },
    createUsername: { type: 'string' },
    isAdmin: { type: Boolean },
    /**
     * isSlave:true
     * 关联租户时创建的用户
     * 例如关联了供应商租户，同时创建了登录用户
     */
    isSlave: { type: Boolean },

    roleCode: { type: 'string' },
    roleName: { type: 'string' },
    quicklyMenus: { type: 'array' }
  };

  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('User', _schema, 'users');
};
